﻿//VPOLYLINE.JS
function InfoState(map)
{
    this._state={};
    this._curState=null;
    this._f=1;
    this.map=map;
}
InfoState.prototype=
{
    addItem:function(item)
    {
        if(this._state[item])
        {
            alert('item exist');
            return;
        }
        this._state[item]=
        {
            ids:{},//索引
            f:1//存在
        };
    }
    
    // add(1) ready(-1)
    ,ready:function(item)
    {
        if(!this._state[item])
        {
            alert('ready err');
            return;
        }
        this.clear(item);
        this._curState=this._state[item];//1
        this._f=this._curState.f==1?-1:1;//切换状态1 -> -1  -1 -> 1
        this._curState.f=this._f;//-1
    }
    ,getState:function(id)
    {
        var ids=this._curState.ids;
        if(ids[id])
        {
            ids[id]=this._f;//1
            return true;
        }
        else
        {
            ids[id]=this._f;
            return false;
        }
    }
    ,clear:function(item)
    {
        if(!this._state[item])
        {
            alert('ready err');
            return;
        }
        var ids=this._state[item].ids;
        var f=this._state[item].f;
        for(var id in ids)
        {
            if(ids[id]!=f)
            {
                delete ids[id];
                var elm=$(id);
                if(elm)
                {
                    this.map.separateObj(elm);
                    elm.parentNode.removeChild(elm);
                }
            }
        }
    }
};